#!/usr/bin/env node

const cp = require('child_process');
console.log(`I am father process.PID:${process.pid}`);

const son = cp.fork('./11-ipc-child.js'),
      dau = cp.fork('./11-ipc-child.js');

son.on('message',(msg) => {
  console.log(`I have a son with PID:${msg}`);
});

dau.on('message',(msg) => {
  console.log(`I have a daughter with PID:${msg}`);
});

setTimeout(()=>{
  son.send('work hard');
} ,2000);

setTimeout(() => {
  dau.send('study hard');
},4000);

setTimeout(() => {
  son.kill('SIGINT');
  dau.kill('SIGINT');
  process.exit();
},6000);

